import Vue from 'vue'
import Axios from 'axios'

// const debug = process.env.NODE_ENV !== 'production'


Vue.prototype.$http = (opt, cb, auth) => {
  let headers = {
    'Authorization': auth || server.auth
  }
  if (opt.method === 'POST') {
    headers['Content-Type'] = 'application/json'
  }
  Axios({
    url: opt.url,
    method: opt.method,
    baseURL: server.url,
    headers: headers,
    data: opt.data
  })
    .then(res => {
      cb(res.data)
    })
    .catch(err => {
      console.error(err)
    })
}

window.toQS = (body) => {
  let qs = '?'
  for (let key in body) {
    qs += `${key}=${body[key]}&`
  }
  return qs.substring(0, qs.length - 1)
}

window.SALE_LEVEL = {
  '9': '高级总监',
  '8': '正式总监',
  '7': '见习总监',
  '6': '高级经理',
  '5': '正式经理',
  '4': '见习经理',
  '3': '高级业务员',
  '2': '正式业务员',
  '1': '见习业务员'
}


